package com.zhouyiquan.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhouyiquan.entity.Province;
import com.zhouyiquan.service.ProvinceService;
import com.zhouyiquan.service.impl.ProvinceServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author: 周益全（https://www.zhouyiquan.site）
 * @Date: Created in 2022/09
 * @Descript:
 */
@WebServlet("/provinceServlet")
public class ProvinceServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/*        ProvinceService service = new ProvinceServiceImpl();
        List<Province> list = service.findAll();
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(list);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
        System.out.println(json);*/


        ProvinceService service = new ProvinceServiceImpl();
        String json = service.findAllJson();
        System.out.println(json);

        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }
}
